package com.itcast.mybatis;

import com.itcast.mybatis.entity.Payment;
import com.itcast.mybatis.mapper.PaymentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

public class TestMybatis {

    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";

        InputStream inputStream = Resources.getResourceAsStream(resource);

        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);


        SqlSession sqlSession = factory.openSession();


        //Map<String,Object> paramMap = new HashMap();
        //paramMap.put("id",1);

        //List<Payment> list =  sqlSession.selectList("com.itcast.mybatis.mapper.PaymentMapper.selectById",paramMap);

        PaymentMapper paymentMapper = sqlSession.getMapper(PaymentMapper.class);

        Payment payment = paymentMapper.selectById(1);

        System.out.println(payment);

        Payment payment2 = paymentMapper.selectById(1);

        System.out.println(payment2);

        sqlSession.commit();

        sqlSession.close();

    }

    @Test
    public void testDemo(){

    }
}
